//
//  SwiftConfig.swift
//  iOSComponentProjrect
//
//  Created by 帅棋 on 2020/8/28.
//  Copyright © 2020 WG. All rights reserved.
//

import Foundation
import UIKit


// 屏幕宽度
let Screen_WIDTH = UIScreen.main.bounds.size.width
// 屏幕高度
let Screen_HEIGHT = UIScreen.main.bounds.size.height
 
// 状态栏高度
let StatusBar_HEIGHT: CGFloat = is_iPhoneXSeries() ? 44 : 20
 
// 导航栏高度
let Nav_HEIGHT: CGFloat = is_iPhoneXSeries() ? 88.0 : 64.0
 
// tabbar高度
let TabBar_HEIGHT: CGFloat = is_iPhoneXSeries() ? 83.0 : 49.0
 
// tabbar 安全区域的高度
let TabBar_Safe_HEIGHT: CGFloat = is_iPhoneXSeries() ? 34.0 : 0.0
 
 
// AppDelegate
let App_Delegate = UIApplication.shared.delegate
 
// Window
let KeyWindow = UIApplication.shared.delegate?.window
 
// Default
let User_Defaults = UserDefaults.standard
 
// 沙盒路径
let Document_Path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
 
// 字符串是否为URL
func is_URLString(ref: String) -> (Bool) {
    var result = false;
    if (!ref.isEmpty && (ref.hasPrefix("https://") || ref.hasPrefix("http://"))) {
        result = true;
    }
    return result;
}
 
// 字符串中是否包含某字符串
func StringContainsSubString(string: String, subString: String) -> (Bool) {
    let range = string.range(of: subString);
    if (range == nil) {
        return false;
    }
    return true;
}
 
// 十进制颜色
func RGBCOLOR(r: CGFloat, g: CGFloat, b: CGFloat) -> (UIColor) {
    return RGBACOLOR(r: r, g: g, b: b, a: 1.0);
}
func RGBACOLOR(r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) -> (UIColor) {
    return UIColor(red: r, green: g, blue: b, alpha: a);
}
 
// 16进制颜色转UIColor
func HEXCOLOR(c: UInt64) -> (UIColor) {
    let redValue = CGFloat((c & 0xFF0000) >> 16)/255.0
    let greenValue = CGFloat((c & 0xFF00) >> 8)/255.0
    let blueValue = CGFloat(c & 0xFF)/255.0
    return UIColor(red: redValue, green: greenValue, blue: blueValue, alpha: 1.0);
}

// 字体
func FONT(size: CGFloat) -> (UIFont) {
    let fontName : String = "PingFangSC-Semibold"
    let font: UIFont = UIFont(name:fontName , size: size)!
    return font
}
 
// 加粗字体
func BOLDFONT(size: CGFloat) -> (UIFont) {
    let fontName : String = "PingFangSC-Semibold"
    let font = UIFont(name: fontName, size: size)
    return font!
}
 

/**
 布局转化
 round  如果参数是小数  则求本身的四舍五入.
 ceil   如果参数是小数  则求最小的整数但不小于本身.
 floor  如果参数是小数  则求最大的整数但不大于本身.
*/
func Adaptive_w_375(w: CGFloat) -> (CGFloat) {
    let new_width = round((w)*UIScreen.main.bounds.size.width/375.0);
    return new_width;
}
 
 
// 适配 判断系统版本
func AdaptiveiOSSystem(version: Float) -> (Bool) {
    let sysVer = Float(UIDevice.current.systemVersion) ?? 0.0;
    if (sysVer >= version) {
        return true;
    }
    return false;
}

/*----------------------------- App store -----------------------------------*/

 
// APPID
let APP_ID = "";
 
// iOS 11 以下的评价列表跳转
func APP_OPEN_EVALUATE() -> (String) {
    return "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=" + APP_ID;
}
 
// iOS 11 的评价跳转
func APP_OPEN_EVALUATE_IOS11() -> (String) {
    return "itms-apps://itunes.apple.com/cn/app/id" + APP_ID + "?mt=8&action=write-review";
}
 
// 获取AppStore上对应APPID的应用信息
func APP_VERSION_INFO() -> (String) {
    return "https://itunes.apple.com/lookup?id=" + APP_ID;
}
 
// APP的下载链接
func APP_DOWNLOAD_URL() -> (String) {
    return "https://itunes.apple.com/app/id" + APP_ID;
}
 
 
/*-----------------------------机型判断-----------------------------------*/

// 判断是否设备是iphoneX系列
func is_iPhoneXSeries() -> (Bool) {
    if #available(iOS 11.0, *) {
        var window:UIWindow = UIApplication.shared.keyWindow!
            if #available(iOS 13.0, *) {
                window = UIApplication.shared.windows.filter({ $0.isKeyWindow }).last!
            }
        if window.safeAreaInsets.bottom > 0 {
            return true;
        }else{
            return false;
        }
    }
    return false;
}
 
// 判断iPhoneX
func is_iPhoneX() -> (Bool) {
    return CompareIPhoneSize(size: CGSize(width: 1125, height: 2436));
}
 
// 判断iPhoneXS
func is_iPhoneXS() -> (Bool) {
    return CompareIPhoneSize(size: CGSize(width: 1125, height: 2436));
}
 
// 判断iPHoneXR
func is_iPhoneXR() -> (Bool) {
    return CompareIPhoneSize(size: CGSize(width: 828, height: 1792));
}
 
// 判断iPhoneXS Max
func is_iPhone_Xs_11_Max() -> (Bool) {
    return CompareIPhoneSize(size: CGSize(width: 1242, height: 2688));
}
 
// 判断iPhone12_Max
func is_iPhone12_Max() -> (Bool) {
    return CompareIPhoneSize(size: CGSize(width: 1284, height: 2778));
}
 
// 判断iPhone12 13 mini
func is_iPhoneMini() -> (Bool) {
    return CompareIPhoneSize(size: CGSize(width: 1080, height: 2340));
}
 
// 判断iPhone12
func is_iPhone12() -> (Bool) {
    return CompareIPhoneSize(size: CGSize(width: 1170, height: 2532));
}
 
/// 判断iPhone Plus
func is_iPhonePlus() -> (Bool) {
    return CompareIPhoneSize(size: CGSize(width: 1080, height: 1920));
}
 
/// 判断iPhone 4.7屏幕
func is_iPhone6_8() -> (Bool) {
    return CompareIPhoneSize(size: CGSize(width: 750, height: 1334));
}
/// 判断iPhone 5S屏幕
func is_iPhone5S() -> (Bool) {
    return CompareIPhoneSize(size: CGSize(width: 640, height: 960));
}
 
// 设备是否是iPad
func is_iPad() -> (Bool) {
    if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad) {
        return true;
    }
    return false;
}
 
func CompareIPhoneSize(size: CGSize) -> (Bool) {
    if (!is_iPad()) {
        guard let currentSize = UIScreen.main.currentMode?.size else {
            return false;
        }
        if (__CGSizeEqualToSize(size, currentSize)) {
            return true;
        }
    }
    return false;
}




